package com.finance.cooperate.strategy.core.strategy;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName StrategyScope
 * @Description 策略执行缓存
 * @Author shenanxin
 * @Date 2023/8/23 15:46
 * @Modify ...
 */
@Component
@Scope(value = WebApplicationContext.SCOPE_REQUEST,
        proxyMode = ScopedProxyMode.TARGET_CLASS)
public class StrategyScope {

    // 各规则处理后结果
    private Map<Class<? extends StrategyHandler>, Strategy> strategyResult = new HashMap<>();

    // 是否命中
    private boolean isHit = false;

    // 用户 Id
    private String uid;

    // 申请id
    private String applyId;

    // 执行模型id
    private Long modelId;

    // 贷款次数
    private Long loanNum;

    // 初始分
    private Double initialScore;

    // 最终分
    private Double finalScore;


    // 流水号
    private String recodeId;

    // 输出特征
    private Map<String, String> featureMap;


    public void putResult(Class<? extends StrategyHandler> c, Strategy t) {
        this.strategyResult.put(c, t);
    }

    public Strategy getResult(Class<? extends StrategyHandler> c) {
        return this.strategyResult.getOrDefault(c, null);
    }


    public void setHit(boolean hit) {
        isHit = hit;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public boolean isHit() {
        return isHit;
    }

    public Long getLoanNum() {
        return loanNum;
    }

    public void setLoanNum(Long loanNum) {
        this.loanNum = loanNum;
    }

    public String getRecodeId() {
        return recodeId;
    }

    public void setRecodeId(String recodeId) {
        this.recodeId = recodeId;
    }

    public Double getInitialScore() {
        return initialScore;
    }

    public void setInitialScore(Double initialScore) {
        this.initialScore = initialScore;
    }

    public Double getFinalScore() {
        return finalScore;
    }

    public void setFinalScore(Double finalScore) {
        this.finalScore = finalScore;
    }

    public String getApplyId() {
        return applyId;
    }

    public void setApplyId(String applyId) {
        this.applyId = applyId;
    }

    public Long getModelId() {
        return modelId;
    }

    public void setModelId(Long modelId) {
        this.modelId = modelId;
    }

    public Map<String, String> getFeatureMap() {
        return featureMap;
    }

    public void setFeatureMap(Map<String, String> featureMap) {
        this.featureMap = featureMap;
    }
}
